﻿var token = getCookie("token");
var adminid = getCookie("adminid");

/*获取sources中的参数值*/
function getUrlArgStr(values) {
    var q = location.search.substr(1);
    var qs = q.split('&');
    var argStr = '';
    if (qs) {
        for (var i = 0; i < qs.length; i++) {
            if (values == qs[i].substring(0, qs[i].indexOf('='))) {
                argStr = qs[i].substring(qs[i].indexOf('=') + 1);
                break;
            }

        }
    }
    return argStr;
}

/*获取问好传值*/
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = decodeURI(window.location.search).substr(1).match(reg);
    if (r != null)
        return unescape(r[2]);
    return null;
}
//删除左右两端的空格
function trim(str){ 
    return str.replace(/(^\s*)|(\s*$)/g, "");
}
//显示消息
function Alert(msg) {
    toast.show(msg);
    //alert(msg);
}
//设置cookies
function SetCookie(name, value, Days) {
    if (Days == null) Days = 30;
    //var Days = 30; //设置Cookie有效时间
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);  
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
}
//获取cookies
function getCookie(name)       
{
    var arr = document.cookie.match(new RegExp("(^| )" +  name  + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;

}
//删除cookies
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

function islogin() {
    token = getCookie("adminname");
 
    if (token == undefined || token == "" || token == null) {
        window.location.href = "login.html";
    }
  
}

//日期格式化
function GetDate(time) {
    if (time == null || time == "") return "";
    if (time.length < 15)
        return time;
    return time.toString().replace("T", " ").substring(0, 19);
}
//日期格式化
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month  
        "d+": this.getDate(),    //day  
        "h+": this.getHours(),   //hour  
        "m+": this.getMinutes(), //minute  
        "s+": this.getSeconds(), //second  
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter  
        "S": this.getMilliseconds() //millisecond  
    }
    if (/(y+)/.test(format))
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}
//返回上一页
function back() {
    var backurl = document.referrer.toString();
    if (backurl == null || backurl == "")
        backurl = "list.html";
    document.location.href = backurl;
}